/***************************************************************
 * Name:      genobotsMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Ramon van Dam, Bart van der Drift & Susan Laraghy
 * Created:   2008-10-20
 * Copyright: Ramon van Dam, Bart van der Drift & Susan Laraghy
 * License:
 **************************************************************/

#include "wx_pch.h"
#include "genobotsMain.h"
#include <wx/msgdlg.h>

//(*InternalHeaders(genobotsFrame)
#include <wx/bitmap.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)
#include "SourceDialog.h"
#include "PlotWindow.h"

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(genobotsFrame)
const long genobotsFrame::ID_STATICTEXT4 = wxNewId();
const long genobotsFrame::ID_TREECTRL1 = wxNewId();
const long genobotsFrame::ID_STATICTEXT22 = wxNewId();
const long genobotsFrame::ID_TEXTCTRL4 = wxNewId();
const long genobotsFrame::ID_CHECKBOX3 = wxNewId();
const long genobotsFrame::ID_PANEL2 = wxNewId();
const long genobotsFrame::ID_GENOCANVAS = wxNewId();
const long genobotsFrame::ID_STATICTEXT5 = wxNewId();
const long genobotsFrame::ID_STATICTEXT6 = wxNewId();
const long genobotsFrame::ID_STATICTEXT7 = wxNewId();
const long genobotsFrame::ID_STATICTEXT8 = wxNewId();
const long genobotsFrame::ID_STATICTEXT9 = wxNewId();
const long genobotsFrame::ID_STATICTEXT10 = wxNewId();
const long genobotsFrame::ID_STATICTEXT13 = wxNewId();
const long genobotsFrame::ID_STATICTEXT14 = wxNewId();
const long genobotsFrame::ID_STATICTEXT11 = wxNewId();
const long genobotsFrame::ID_STATICTEXT12 = wxNewId();
const long genobotsFrame::ID_STATICTEXT15 = wxNewId();
const long genobotsFrame::ID_CHECKBOX1 = wxNewId();
const long genobotsFrame::ID_GRID1 = wxNewId();
const long genobotsFrame::ID_TEXTCTRL3 = wxNewId();
const long genobotsFrame::ID_PANEL3 = wxNewId();
const long genobotsFrame::ID_STATICTEXT19 = wxNewId();
const long genobotsFrame::ID_SPINCTRL5 = wxNewId();
const long genobotsFrame::ID_STATICTEXT20 = wxNewId();
const long genobotsFrame::ID_SPINCTRL6 = wxNewId();
const long genobotsFrame::ID_STATICTEXT16 = wxNewId();
const long genobotsFrame::ID_SPINCTRL2 = wxNewId();
const long genobotsFrame::ID_STATICTEXT17 = wxNewId();
const long genobotsFrame::ID_SPINCTRL3 = wxNewId();
const long genobotsFrame::ID_STATICTEXT18 = wxNewId();
const long genobotsFrame::ID_SPINCTRL4 = wxNewId();
const long genobotsFrame::ID_STATICTEXT28 = wxNewId();
const long genobotsFrame::ID_SPINCTRL10 = wxNewId();
const long genobotsFrame::ID_STATICTEXT21 = wxNewId();
const long genobotsFrame::ID_CHECKBOX2 = wxNewId();
const long genobotsFrame::ID_STATICTEXT23 = wxNewId();
const long genobotsFrame::ID_CHECKBOX4 = wxNewId();
const long genobotsFrame::ID_STATICTEXT24 = wxNewId();
const long genobotsFrame::ID_SPINCTRL7 = wxNewId();
const long genobotsFrame::ID_STATICTEXT25 = wxNewId();
const long genobotsFrame::ID_SPINCTRL8 = wxNewId();
const long genobotsFrame::ID_STATICTEXT26 = wxNewId();
const long genobotsFrame::ID_SPINCTRL9 = wxNewId();
const long genobotsFrame::ID_STATICTEXT27 = wxNewId();
const long genobotsFrame::ID_CHOICE1 = wxNewId();
const long genobotsFrame::ID_PANEL4 = wxNewId();
const long genobotsFrame::ID_NOTEBOOK1 = wxNewId();
const long genobotsFrame::ID_STATICTEXT1 = wxNewId();
const long genobotsFrame::ID_SLIDER1 = wxNewId();
const long genobotsFrame::ID_SPINCTRL1 = wxNewId();
const long genobotsFrame::ID_STATICTEXT2 = wxNewId();
const long genobotsFrame::ID_TEXTCTRL1 = wxNewId();
const long genobotsFrame::ID_STATICTEXT3 = wxNewId();
const long genobotsFrame::ID_TEXTCTRL2 = wxNewId();
const long genobotsFrame::ID_BUTTON1 = wxNewId();
const long genobotsFrame::ID_BUTTON2 = wxNewId();
const long genobotsFrame::ID_BUTTON3 = wxNewId();
const long genobotsFrame::ID_BUTTON4 = wxNewId();
const long genobotsFrame::ID_PANEL1 = wxNewId();
const long genobotsFrame::idMenuNew = wxNewId();
const long genobotsFrame::isMenuSourceEditor = wxNewId();
const long genobotsFrame::isMenuPlot = wxNewId();
const long genobotsFrame::idMenuQuit = wxNewId();
const long genobotsFrame::idMenuBotsAddSuperBot = wxNewId();
const long genobotsFrame::idMenuLoopStart = wxNewId();
const long genobotsFrame::idMenuLoopStep = wxNewId();
const long genobotsFrame::idMenuLoopStop = wxNewId();
const long genobotsFrame::idMenuAbout = wxNewId();
const long genobotsFrame::ID_STATUSBAR1 = wxNewId();
const long genobotsFrame::ID_TOOL_RESTART = wxNewId();
const long genobotsFrame::ID_TOOL_CLEAR = wxNewId();
const long genobotsFrame::ID_ADD_SUPERBOT = wxNewId();
const long genobotsFrame::ID_TOOL_BOTS = wxNewId();
const long genobotsFrame::ID_TOOL_FOOD = wxNewId();
const long genobotsFrame::ID_TOOL_PLOT = wxNewId();
const long genobotsFrame::ID_TOOL_SOURCE = wxNewId();
const long genobotsFrame::ID_TOOL_NEW = wxNewId();
const long genobotsFrame::ID_TOOL_START = wxNewId();
const long genobotsFrame::ID_TOOL_STOP = wxNewId();
const long genobotsFrame::ID_TOOLBAR1 = wxNewId();
const long genobotsFrame::ID_TIMER1 = wxNewId();
const long genobotsFrame::ID_DELETE_BOT = wxNewId();
const long genobotsFrame::ID_ADD_BOT = wxNewId();
//*)

BEGIN_EVENT_TABLE(genobotsFrame,wxFrame)
    //(*EventTable(genobotsFrame)
    //*)
END_EVENT_TABLE()

// event table for the drawing canvas
BEGIN_EVENT_TABLE(GenoCanvas, wxWindow)
  EVT_ERASE_BACKGROUND  (GenoCanvas::OnEraseBackground)
  EVT_PAINT             (GenoCanvas::OnPaint)
  EVT_SIZE              (GenoCanvas::OnSize)
  EVT_LEFT_UP           (GenoCanvas::OnLeftUp)
  EVT_RIGHT_UP          (GenoCanvas::OnRightUp)
END_EVENT_TABLE()

genobotsFrame::genobotsFrame(wxWindow* parent,wxWindowID id)
{
    srand ( time(NULL) );
    genobots = new GenoBots(15, 15);
    genobots->Randomize(g_tics);
    g_running  = false;
    g_topspeed = false;
    g_tics     = 0;

    //(*Initialize(genobotsFrame)
    wxBoxSizer* BoxSizer4;
    wxBoxSizer* BoxSizer5;
    wxMenuItem* MenuItem2;
    wxFlexGridSizer* FlexGridSizer3;
    wxMenuItem* MenuItem1;
    wxFlexGridSizer* FlexGridSizer2;
    wxBoxSizer* BoxSizer2;
    wxMenu* Menu1;
    wxMenuItem* menuRightBotDelete;
    wxBoxSizer* BoxSizer1;
    wxMenuBar* MenuBar1;
    wxStaticBoxSizer* StaticBoxSizer1;
    wxFlexGridSizer* FlexGridSizer1;
    wxBoxSizer* BoxSizer3;
    wxMenu* Menu2;

    Create(parent, wxID_ANY, _("GenoBots"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(500,500));
    Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(120,224), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    BoxSizer1 = new wxBoxSizer(wxVERTICAL);
    BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
    Panel2 = new wxPanel(Panel1, ID_PANEL2, wxDefaultPosition, wxSize(135,394), wxTAB_TRAVERSAL, _T("ID_PANEL2"));
    BoxSizer4 = new wxBoxSizer(wxVERTICAL);
    StaticText4 = new wxStaticText(Panel2, ID_STATICTEXT4, _("Loaded superbots:"), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE, _T("ID_STATICTEXT4"));
    BoxSizer4->Add(StaticText4, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    treeLoadedBots = new wxTreeCtrl(Panel2, ID_TREECTRL1, wxDefaultPosition, wxSize(144,366), wxTR_DEFAULT_STYLE, wxDefaultValidator, _T("ID_TREECTRL1"));
    treeLoadedBots->SetBackgroundColour(wxColour(255,255,213));
    BoxSizer4->Add(treeLoadedBots, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText17 = new wxStaticText(Panel2, ID_STATICTEXT22, _("Log:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT22"));
    BoxSizer4->Add(StaticText17, 0, wxTOP|wxLEFT|wxRIGHT|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    txtLog = new wxTextCtrl(Panel2, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE, wxDefaultValidator, _T("ID_TEXTCTRL4"));
    txtLog->SetBackgroundColour(wxColour(255,255,213));
    BoxSizer4->Add(txtLog, 1, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    chkUseLog = new wxCheckBox(Panel2, ID_CHECKBOX3, _("Use log"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX3"));
    chkUseLog->SetValue(true);
    BoxSizer4->Add(chkUseLog, 0, wxTOP|wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel2->SetSizer(BoxSizer4);
    BoxSizer4->SetSizeHints(Panel2);
    BoxSizer2->Add(Panel2, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    genoCanvas = new GenoCanvas(Panel1, genobots);
    BoxSizer2->Add(genoCanvas, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    Notebook1 = new wxNotebook(Panel1, ID_NOTEBOOK1, wxDefaultPosition, wxSize(170,391), 0, _T("ID_NOTEBOOK1"));
    Panel3 = new wxPanel(Notebook1, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL3"));
    BoxSizer5 = new wxBoxSizer(wxVERTICAL);
    FlexGridSizer2 = new wxFlexGridSizer(0, 2, 0, 0);
    FlexGridSizer2->AddGrowableCol(1);
    StaticText5 = new wxStaticText(Panel3, ID_STATICTEXT5, _("Superbot:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
    FlexGridSizer2->Add(StaticText5, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    stcBotSuperbot = new wxStaticText(Panel3, ID_STATICTEXT6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
    FlexGridSizer2->Add(stcBotSuperbot, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText6 = new wxStaticText(Panel3, ID_STATICTEXT7, _("Starttic:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
    FlexGridSizer2->Add(StaticText6, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    stcBotStarttic = new wxStaticText(Panel3, ID_STATICTEXT8, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
    FlexGridSizer2->Add(stcBotStarttic, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText7 = new wxStaticText(Panel3, ID_STATICTEXT9, _("Direction:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT9"));
    FlexGridSizer2->Add(StaticText7, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    stcBotDirection = new wxStaticText(Panel3, ID_STATICTEXT10, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT10"));
    FlexGridSizer2->Add(stcBotDirection, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText9 = new wxStaticText(Panel3, ID_STATICTEXT13, _("Health:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT13"));
    FlexGridSizer2->Add(StaticText9, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    stcBotHealth = new wxStaticText(Panel3, ID_STATICTEXT14, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT14"));
    FlexGridSizer2->Add(stcBotHealth, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText8 = new wxStaticText(Panel3, ID_STATICTEXT11, _("Line Nr:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT11"));
    FlexGridSizer2->Add(StaticText8, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    stcBotLineNr = new wxStaticText(Panel3, ID_STATICTEXT12, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT12"));
    FlexGridSizer2->Add(stcBotLineNr, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText10 = new wxStaticText(Panel3, ID_STATICTEXT15, _("Follow:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT15"));
    FlexGridSizer2->Add(StaticText10, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    chkBotFollow = new wxCheckBox(Panel3, ID_CHECKBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
    chkBotFollow->SetValue(true);
    FlexGridSizer2->Add(chkBotFollow, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer5->Add(FlexGridSizer2, 0, wxALL|wxEXPAND|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL, 0);
    grdBotMemory = new wxGrid(Panel3, ID_GRID1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_GRID1"));
    BoxSizer5->Add(grdBotMemory, 0, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    txtBotCode = new wxTextCtrl(Panel3, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxSize(131,283), wxTE_MULTILINE|wxTE_RICH2, wxDefaultValidator, _T("ID_TEXTCTRL3"));
    txtBotCode->SetBackgroundColour(wxColour(255,255,213));
    BoxSizer5->Add(txtBotCode, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel3->SetSizer(BoxSizer5);
    BoxSizer5->Fit(Panel3);
    BoxSizer5->SetSizeHints(Panel3);
    Panel4 = new wxPanel(Notebook1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4"));
    FlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
    StaticText14 = new wxStaticText(Panel4, ID_STATICTEXT19, _("Init bot chance"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT19"));
    FlexGridSizer3->Add(StaticText14, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnInitBotChance = new wxSpinCtrl(Panel4, ID_SPINCTRL5, _T("8"), wxDefaultPosition, wxDefaultSize, 0, 1, 1000, 8, _T("ID_SPINCTRL5"));
    spnInitBotChance->SetValue(_T("8"));
    FlexGridSizer3->Add(spnInitBotChance, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText15 = new wxStaticText(Panel4, ID_STATICTEXT20, _("Init bot health"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT20"));
    FlexGridSizer3->Add(StaticText15, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnInitBotHealth = new wxSpinCtrl(Panel4, ID_SPINCTRL6, _T("100"), wxDefaultPosition, wxDefaultSize, 0, 1, 10000, 100, _T("ID_SPINCTRL6"));
    spnInitBotHealth->SetValue(_T("100"));
    FlexGridSizer3->Add(spnInitBotHealth, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText11 = new wxStaticText(Panel4, ID_STATICTEXT16, _("Food chance"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT16"));
    FlexGridSizer3->Add(StaticText11, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnFoodChance = new wxSpinCtrl(Panel4, ID_SPINCTRL2, _T("8"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 8, _T("ID_SPINCTRL2"));
    spnFoodChance->SetValue(_T("8"));
    FlexGridSizer3->Add(spnFoodChance, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText12 = new wxStaticText(Panel4, ID_STATICTEXT17, _("Food interval"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT17"));
    FlexGridSizer3->Add(StaticText12, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnFoodInterval = new wxSpinCtrl(Panel4, ID_SPINCTRL3, _T("50"), wxDefaultPosition, wxDefaultSize, 0, 1, 1000, 50, _T("ID_SPINCTRL3"));
    spnFoodInterval->SetValue(_T("50"));
    FlexGridSizer3->Add(spnFoodInterval, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText13 = new wxStaticText(Panel4, ID_STATICTEXT18, _("Food health"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT18"));
    FlexGridSizer3->Add(StaticText13, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnFoodHealth = new wxSpinCtrl(Panel4, ID_SPINCTRL4, _T("10"), wxDefaultPosition, wxDefaultSize, 0, 1, 1000, 10, _T("ID_SPINCTRL4"));
    spnFoodHealth->SetValue(_T("10"));
    FlexGridSizer3->Add(spnFoodHealth, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText23 = new wxStaticText(Panel4, ID_STATICTEXT28, _("Fight damage"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT28"));
    FlexGridSizer3->Add(StaticText23, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnFightDamage = new wxSpinCtrl(Panel4, ID_SPINCTRL10, _T("20"), wxDefaultPosition, wxDefaultSize, 0, 0, 1000, 20, _T("ID_SPINCTRL10"));
    spnFightDamage->SetValue(_T("20"));
    FlexGridSizer3->Add(spnFightDamage, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText16 = new wxStaticText(Panel4, ID_STATICTEXT21, _("Create offspring"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT21"));
    FlexGridSizer3->Add(StaticText16, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    chkEvolve = new wxCheckBox(Panel4, ID_CHECKBOX2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
    chkEvolve->SetValue(true);
    FlexGridSizer3->Add(chkEvolve, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText18 = new wxStaticText(Panel4, ID_STATICTEXT23, _("Mutate"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT23"));
    FlexGridSizer3->Add(StaticText18, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    chkMutate = new wxCheckBox(Panel4, ID_CHECKBOX4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
    chkMutate->SetValue(true);
    FlexGridSizer3->Add(chkMutate, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText19 = new wxStaticText(Panel4, ID_STATICTEXT24, _("Evo chance/tic"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT24"));
    FlexGridSizer3->Add(StaticText19, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnEvoChance = new wxSpinCtrl(Panel4, ID_SPINCTRL7, _T("8"), wxDefaultPosition, wxDefaultSize, 0, 0, 100, 8, _T("ID_SPINCTRL7"));
    spnEvoChance->SetValue(_T("8"));
    FlexGridSizer3->Add(spnEvoChance, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText20 = new wxStaticText(Panel4, ID_STATICTEXT25, _("Evo amount 1/"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT25"));
    FlexGridSizer3->Add(StaticText20, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnEvoAmount = new wxSpinCtrl(Panel4, ID_SPINCTRL8, _T("20"), wxDefaultPosition, wxDefaultSize, 0, 0, 1000, 20, _T("ID_SPINCTRL8"));
    spnEvoAmount->SetValue(_T("20"));
    FlexGridSizer3->Add(spnEvoAmount, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText21 = new wxStaticText(Panel4, ID_STATICTEXT26, _("Mutate chance"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT26"));
    FlexGridSizer3->Add(StaticText21, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    spnMutateChance = new wxSpinCtrl(Panel4, ID_SPINCTRL9, _T("10"), wxDefaultPosition, wxDefaultSize, 0, 0, 1000, 10, _T("ID_SPINCTRL9"));
    spnMutateChance->SetValue(_T("10"));
    FlexGridSizer3->Add(spnMutateChance, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText22 = new wxStaticText(Panel4, ID_STATICTEXT27, _("Image quality"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT27"));
    FlexGridSizer3->Add(StaticText22, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    chcQuality = new wxChoice(Panel4, ID_CHOICE1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE1"));
    chcQuality->SetSelection( chcQuality->Append(_("Normal")) );
    chcQuality->Append(_("High"));
    FlexGridSizer3->Add(chcQuality, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel4->SetSizer(FlexGridSizer3);
    FlexGridSizer3->Fit(Panel4);
    FlexGridSizer3->SetSizeHints(Panel4);
    Notebook1->AddPage(Panel3, _("Bot"), false);
    Notebook1->AddPage(Panel4, _("Settings"), false);
    BoxSizer2->Add(Notebook1, 0, wxLEFT|wxRIGHT|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, _("General options"));
    FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
    FlexGridSizer1->AddGrowableCol(1);
    StaticText1 = new wxStaticText(Panel1, ID_STATICTEXT1, _("Speed:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
    FlexGridSizer1->Add(StaticText1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    sldSpeed = new wxSlider(Panel1, ID_SLIDER1, 100, 1, 1000, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_SLIDER1"));
    sldSpeed->SetTick(1);
    FlexGridSizer1->Add(sldSpeed, 1, wxTOP|wxBOTTOM|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    spnSpeed = new wxSpinCtrl(Panel1, ID_SPINCTRL1, _T("100"), wxDefaultPosition, wxDefaultSize, 0, 1, 1000, 100, _T("ID_SPINCTRL1"));
    spnSpeed->SetValue(_T("100"));
    FlexGridSizer1->Add(spnSpeed, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Size:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
    FlexGridSizer1->Add(StaticText2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    BoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
    txtNumRows = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("10"), wxDefaultPosition, wxSize(40,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    BoxSizer3->Add(txtNumRows, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("x"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
    BoxSizer3->Add(StaticText3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    txtNumColumns = new wxTextCtrl(Panel1, ID_TEXTCTRL2, _("10"), wxDefaultPosition, wxSize(40,21), 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
    BoxSizer3->Add(txtNumColumns, 0, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
    butNew = new wxButton(Panel1, ID_BUTTON1, _("New"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    BoxSizer3->Add(butNew, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    butClear = new wxButton(Panel1, ID_BUTTON2, _("Clear"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    BoxSizer3->Add(butClear, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    butFood = new wxButton(Panel1, ID_BUTTON3, _("Food"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
    BoxSizer3->Add(butFood, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    butBots = new wxButton(Panel1, ID_BUTTON4, _("Bots"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON4"));
    butBots->Disable();
    BoxSizer3->Add(butBots, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    FlexGridSizer1->Add(BoxSizer3, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 0);
    StaticBoxSizer1->Add(FlexGridSizer1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
    BoxSizer1->Add(StaticBoxSizer1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    Panel1->SetSizer(BoxSizer1);
    BoxSizer1->Fit(Panel1);
    BoxSizer1->SetSizeHints(Panel1);
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    menuFileNew = new wxMenuItem(Menu1, idMenuNew, _("New\tCtrl-N"), wxEmptyString, wxITEM_NORMAL);
    Menu1->Append(menuFileNew);
    menuFileSource = new wxMenuItem(Menu1, isMenuSourceEditor, _("Source editor\tCtrl-E"), _("Edit source code"), wxITEM_NORMAL);
    Menu1->Append(menuFileSource);
    menuFilePlot = new wxMenuItem(Menu1, isMenuPlot, _("Plot\tCtrl-P"), _("Plot the bots"), wxITEM_NORMAL);
    Menu1->Append(menuFilePlot);
    Menu1->AppendSeparator();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu4 = new wxMenu();
    MenuItem3 = new wxMenuItem(Menu4, idMenuBotsAddSuperBot, _("Add superbot\tCtrl-A"), wxEmptyString, wxITEM_NORMAL);
    Menu4->Append(MenuItem3);
    MenuBar1->Append(Menu4, _("Bots"));
    Menu3 = new wxMenu();
    menuLoopStart = new wxMenuItem(Menu3, idMenuLoopStart, _("Start\tCtrl-2"), wxEmptyString, wxITEM_NORMAL);
    Menu3->Append(menuLoopStart);
    menuLoopStep = new wxMenuItem(Menu3, idMenuLoopStep, _("Step\tCtrl-3"), wxEmptyString, wxITEM_NORMAL);
    Menu3->Append(menuLoopStep);
    menuLoopStop = new wxMenuItem(Menu3, idMenuLoopStop, _("Stop\tCtrl-1"), wxEmptyString, wxITEM_NORMAL);
    Menu3->Append(menuLoopStop);
    MenuBar1->Append(Menu3, _("Loop"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    statusbar = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[3] = { -1, 100, 60 };
    int __wxStatusBarStyles_1[3] = { wxSB_NORMAL, wxSB_NORMAL, wxSB_NORMAL };
    statusbar->SetFieldsCount(3,__wxStatusBarWidths_1);
    statusbar->SetStatusStyles(3,__wxStatusBarStyles_1);
    SetStatusBar(statusbar);
    ToolBar1 = new wxToolBar(this, ID_TOOLBAR1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER, _T("ID_TOOLBAR1"));
    ToolBarItem1 = ToolBar1->AddTool(ID_TOOL_RESTART, _("Restart"), wxBitmap(wxImage(_T("images\\delete.png"))), wxNullBitmap, wxITEM_NORMAL, _("Restart"), _("Restart"));
    ToolBarItem2 = ToolBar1->AddTool(ID_TOOL_CLEAR, _("Clear the grid"), wxBitmap(wxImage(_T("images\\clear.png"))), wxNullBitmap, wxITEM_NORMAL, _("Clear the grid"), _("Clear the grid"));
    ToolBarItem3 = ToolBar1->AddTool(ID_ADD_SUPERBOT, _("Add superbot"), wxBitmap(wxImage(_T("images/superbot.png"))), wxBitmap(wxImage(_T("images/superbot.png"))), wxITEM_NORMAL, _("Add superbot"), _("Add superbot"));
    ToolBarItem4 = ToolBar1->AddTool(ID_TOOL_BOTS, _("Add bots"), wxBitmap(wxImage(_T("images\\bug.png"))), wxBitmap(wxImage(_T("images\\bug_disabled.png"))), wxITEM_NORMAL, _("Add bots"), _("Add bots"));
    ToolBarItem5 = ToolBar1->AddTool(ID_TOOL_FOOD, _("Add food"), wxBitmap(wxImage(_T("images\\food.png"))), wxNullBitmap, wxITEM_NORMAL, _("Add food"), _("Add food"));
    ToolBarItem6 = ToolBar1->AddTool(ID_TOOL_PLOT, _("Plot"), wxBitmap(wxImage(_T("images\\chart_curve.png"))), wxBitmap(wxImage(_T("images\\chart_curve.png"))), wxITEM_NORMAL, _("Show a plot"), _("Show a plot"));
    ToolBarItem7 = ToolBar1->AddTool(ID_TOOL_SOURCE, _("Source editor"), wxBitmap(wxImage(_T("images\\page_code.png"))), wxNullBitmap, wxITEM_NORMAL, _("Source editor"), _("Source editor"));
    ToolBar1->AddSeparator();
    ToolBarItem8 = ToolBar1->AddTool(ID_TOOL_NEW, _("New"), wxBitmap(wxImage(_T("images\\new.png"))), wxBitmap(wxImage(_T("images\\new_disabled.png"))), wxITEM_NORMAL, _("Create a new grid"), _("Create a new grid"));
    ToolBarItem9 = ToolBar1->AddTool(ID_TOOL_START, _("Start"), wxBitmap(wxImage(_T("images\\control_play_blue.png"))), wxBitmap(wxImage(_T("images\\control_play.png"))), wxITEM_NORMAL, _("Start the main loop"), _("Start the main loop"));
    ToolBarItem10 = ToolBar1->AddTool(ID_TOOL_STOP, _("Stop"), wxBitmap(wxImage(_T("images\\control_pause_blue.png"))), wxBitmap(wxImage(_T("images\\control_pause.png"))), wxITEM_NORMAL, _("Stop the main loop"), _("Stop the main loop"));
    ToolBar1->Realize();
    SetToolBar(ToolBar1);
    g_timer1.SetOwner(this, ID_TIMER1);
    menuRightBotDelete = new wxMenuItem((&menuRightBot), ID_DELETE_BOT, _("Delete this bot"), wxEmptyString, wxITEM_NORMAL);
    menuRightBot.Append(menuRightBotDelete);
    menuRightNoBotAddBot = new wxMenuItem((&menuRightNoBot), ID_ADD_BOT, _("Add bot"), wxEmptyString, wxITEM_NORMAL);
    menuRightNoBot.Append(menuRightNoBotAddBot);
    Center();

    Connect(ID_CHECKBOX3,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnChkUseLogClick);
    Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnChkBotFollowClick);
    Connect(ID_SPINCTRL5,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnInitBotChanceChange);
    Connect(ID_SPINCTRL6,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnInitBotHealthChange);
    Connect(ID_SPINCTRL2,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnFoodChanceChange);
    Connect(ID_SPINCTRL3,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnFoodIntervalChange);
    Connect(ID_SPINCTRL4,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnFoodHealthChange);
    Connect(ID_SPINCTRL10,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnFightDamageChange);
    Connect(ID_CHECKBOX2,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnChkEvolveClick);
    Connect(ID_CHECKBOX4,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnChkMutateClick);
    Connect(ID_SPINCTRL7,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnEvoChanceChange);
    Connect(ID_SPINCTRL8,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnEvoAmountChange);
    Connect(ID_SPINCTRL9,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnMutateChanceChange);
    Connect(ID_CHOICE1,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnChcQualitySelect);
    Connect(ID_SLIDER1,wxEVT_SCROLL_THUMBTRACK,(wxObjectEventFunction)&genobotsFrame::OnSldSpeedCmdScrollThumbTrack);
    Connect(ID_SLIDER1,wxEVT_SCROLL_CHANGED,(wxObjectEventFunction)&genobotsFrame::OnSldSpeedCmdScrollChanged);
    Connect(ID_SPINCTRL1,wxEVT_COMMAND_SPINCTRL_UPDATED,(wxObjectEventFunction)&genobotsFrame::OnSpnSpeedChange);
    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnButNewClick);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnbutClearClick);
    Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnButFoodClick);
    Connect(ID_BUTTON4,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnButBotsClick);
    Connect(idMenuNew,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuFileNewSelected);
    Connect(isMenuSourceEditor,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuFileSourceSelected);
    Connect(isMenuPlot,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuFilePlotSelected);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnQuit);
    Connect(idMenuBotsAddSuperBot,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuBotsAddSuperBotSelected);
    Connect(idMenuLoopStart,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuLoopStartSelected);
    Connect(idMenuLoopStep,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuLoopStepSelected);
    Connect(idMenuLoopStop,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuLoopStopSelected);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnAbout);
    Connect(ID_TOOL_RESTART,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolBarRestartClick);
    Connect(ID_TOOL_CLEAR,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolBarClearClick);
    Connect(ID_ADD_SUPERBOT,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolBarSuperbotClick);
    Connect(ID_TOOL_BOTS,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolAddBotsClicked);
    Connect(ID_TOOL_FOOD,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolFoodClicked);
    Connect(ID_TOOL_PLOT,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolPlotClicked);
    Connect(ID_TOOL_SOURCE,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolBarSourceClick);
    Connect(ID_TOOL_NEW,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolnewClicked);
    Connect(ID_TOOL_START,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolStartClicked);
    Connect(ID_TOOL_STOP,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&genobotsFrame::OnToolStopClicked);
    Connect(ID_TIMER1,wxEVT_TIMER,(wxObjectEventFunction)&genobotsFrame::OnG_timer1Trigger);
    Connect(ID_DELETE_BOT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuRightBotDeleteSelected);
    Connect(ID_ADD_BOT,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&genobotsFrame::OnMenuRightNoBotAddBotSelected);
    //*)
    SetStatusText(_("Welcome to GenoBots!"), 0);

    //ShowFullScreen(true);


    genobots->ChangedAll();
    g_interval = spnSpeed->GetValue();
    g_busy = false;
    genoCanvas->theFrame = this;
    //genobots->drawAll = true;

    // memory
    grdBotMemory->CreateGrid(BOT_NUMMEMCELLS, 1);
    grdBotMemory->SetColFormatNumber(0);
    grdBotMemory->SetColLabelValue(0, _("Val"));
    grdBotMemory->SetColLabelSize(15);
    grdBotMemory->SetRowLabelSize(25);
    grdBotMemory->EnableEditing(false);
    grdBotMemory->EnableDragGridSize(false);

    // settings
    theSettings = new settings();
    genobots->theSettings = theSettings;
    theSettings->log = txtLog;
    theSettings->followBot = chkBotFollow->IsChecked();
    genoCanvas->theSettings = theSettings;

    // add root to tree
    treeRoot = treeLoadedBots->AddRoot(_("Superbots"), 0);
    UpdateTree();

    GetToolBar()->EnableTool(ID_TOOL_BOTS, false);
    GetToolBar()->EnableTool(ID_TOOL_START, false);
    UpdateUI();
    UpdateStatusBar();
    Refresh();
}

genobotsFrame::~genobotsFrame()
{
    //(*Destroy(genobotsFrame)
    //*)
}

void genobotsFrame::OnQuit(wxCommandEvent& event)
{
    OnStop();
    Close();
}

void genobotsFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = _("GenoBots v1.0\n\nCreated by:\n- Ramon van Dam\n- Bart van der Drift\n- Susan Laraghy\n\nMMS 2008 Project");
    wxMessageBox(msg, _("About"));
}

// canvas functions
GenoCanvas::GenoCanvas(wxWindow *parent, GenoBots *theGenobots)
               : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(100, 100), wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER) {
  genobots = theGenobots;
  //SetCursor(*wxCROSS_CURSOR);
  SetBackgroundColour(*wxWHITE);
  drawAll = true;
  selected.first = -1;
  selected.second = -1;
}

GenoCanvas::~GenoCanvas() {

}

// convert a clicked point to a row and column on the grid
wxPoint GenoCanvas::computeCell(wxPoint clickPoint) {
  double x, y;
  x = (((double)clickPoint.x - orig.x) / (genobots->GetRows() * cellsize)) * genobots->GetRows();
  y = (((double)clickPoint.y - orig.y) / (genobots->GetColumns() * cellsize)) * genobots->GetColumns();
  //wxMessageBox(wxString::Format(_("origX %d origY %d clickX %d clickY %d width %d height %d x %f y %f"), orig.x, orig.y, clickPoint.x, clickPoint.y, width, height, x, y), _("Left Click"));
  //wxPoint result = wxPoint(GetRound(x), GetRound(y));
  wxPoint result = wxPoint((int)y, (int)x);
  return result;
}

void GenoCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
    // do nothing. I just don't want the background to be erased, you know.
}

int GenoCanvas::GetMin(int a, int b) {
  return (a < b) ? a : b;
}

int GenoCanvas::GetRound(float f) {
  return (f - floor(f) >= 0.5f) ? int(ceil(f)) : int(floor(f));
}

// paint the current virtual world
void GenoCanvas::OnPaint(wxPaintEvent& event) {
  int i, j;
  wxPaintDC dc(this);
  // retrieve coordinates to redraw
  wxRect surface = GetUpdateRegion().GetBox();
  wxCoord x, y;
  //wxInt32 i0, i1, j0, j1;
  x = surface.GetX();
  y = surface.GetY();
  orig.x = x;
  orig.y = y;
  width = surface.GetWidth();
  height = surface.GetHeight();
  // cellsize
  cellsize = GetMin((width - BORDER * 2) / genobots->GetColumns(), (height - BORDER * 2) / genobots->GetRows());
  // update size variables
  orig.x = width / 2 - (cellsize * genobots->GetColumns()) / 2;
  orig.y = height / 2 - (cellsize * genobots->GetRows()) / 2;

  if(drawAll) {
    //wxMessageBox(wxString::Format(_("Params: (%d %d %d %d)"), x, y, width, height), _("Left Click"));
    // draw background
    dc.SetPen(*wxWHITE_PEN);
    dc.SetBrush(*wxWHITE_BRUSH);
    dc.DrawRectangle(x, y, width, height);
    // light borders
    dc.SetPen(wxPen(wxColour(210, 210, 210)));
    dc.SetBrush(*wxTRANSPARENT_BRUSH);
    for(i = 0; i < genobots->GetRows(); i++) {
       for(j = 0; j < genobots->GetColumns(); j++) {
        dc.DrawRectangle(orig.x + cellsize * j,
          orig.y + cellsize * i,
          cellsize + 1,cellsize + 1);
      }
    }
  }

  // display the bots
  wxImage botImages[genobots->superBots.size() * 4];
  // make correct images for each superbot
  for(i = 0; i < (int)genobots->superBots.size(); i++) {
    botImages[i*4].LoadFile(_("./images/bug1.jpg"));
    botImages[i*4].RotateHue(genobots->superBots[i]->hue);
    botImages[i*4+1] = botImages[i*4].Rotate90(true);
    botImages[i*4+2] = botImages[i*4+1].Rotate90(true);
    botImages[i*4+3] = botImages[i*4].Rotate90(false);
    botImages[i*4].Rescale(cellsize - 1, cellsize - 1, theSettings->quality);
    botImages[i*4+1].Rescale(cellsize - 1, cellsize - 1, theSettings->quality);
    botImages[i*4+2].Rescale(cellsize - 1, cellsize - 1, theSettings->quality);
    botImages[i*4+3].Rescale(cellsize - 1, cellsize - 1, theSettings->quality);
  }
  for(wxInt32 i = 0; i < genobots->GetRows(); i++) {
    for(wxInt32 j = 0; j < genobots->GetColumns(); j++) {
      // check if it has changed
      if(drawAll || genobots->changed[i][j]) {
        if(genobots->bots[i][j] != NULL) {
          switch(genobots->bots[i][j]->direction) {
            case 0:
              dc.DrawBitmap(botImages[genobots->bots[i][j]->mySuperbot->superBotId * 4], orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, true);
              break;
            case 1:
              dc.DrawBitmap(botImages[genobots->bots[i][j]->mySuperbot->superBotId * 4 + 1], orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, true);
              break;
            case 2:
              dc.DrawBitmap(botImages[genobots->bots[i][j]->mySuperbot->superBotId * 4 + 2], orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, true);
              break;
            case 3:
              dc.DrawBitmap(botImages[genobots->bots[i][j]->mySuperbot->superBotId * 4 + 3], orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, true);
              break;
          }
        } else {
          if(genobots->food[i][j]) {
            // food
            dc.SetPen(wxPen(wxColor(150, 255, 150)));
            dc.SetBrush(wxBrush(wxColor(150, 255, 150)));
            dc.DrawRectangle(orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, cellsize - 1, cellsize - 1);
          } else if(!drawAll) {
            // nothing, white
            dc.SetPen(*wxWHITE_PEN);
            dc.SetBrush(*wxWHITE_BRUSH);
            dc.DrawRectangle(orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, cellsize - 1, cellsize - 1);
          }
        }
        // border for the selected
        if(i == selected.first && j == selected.second) {
          dc.SetPen(*wxRED_PEN);
          dc.SetBrush(*wxTRANSPARENT_BRUSH);
          // TODO (Ramon#1#): Correct size
          dc.DrawRectangle(orig.x + j * cellsize + 1, orig.y + i * cellsize + 1, cellsize - 1, cellsize - 1);
        }
      }
    }
  }

  drawAll = false;
}

void GenoCanvas::OnSize(wxSizeEvent& event) {
  // TODO (Ramon#5#): check for canvassize > 0
  drawAll = true;
  event.Skip();
}

// start-button on the toolbar is clicked
void genobotsFrame::OnToolStartClicked(wxCommandEvent& event)
{
  OnStart();
}

// start the main loop
void genobotsFrame::OnStart() {
  if(!g_running) {
    g_timer1.Start(g_interval);
    g_running = true;
    UpdateUI();
  }
}

// stop the main loop
void genobotsFrame::OnStop() {
  if(g_running) {
    g_timer1.Stop();
    g_running = false;
    g_topspeed = false;
    UpdateUI();
  }
}

// go one step further in the world
void genobotsFrame::OnStep() {
  if(!g_busy && genobots->superBots.size()) {
    g_busy = true;
    // produce the next tic
    genobots->NextTic(genoCanvas->selected, g_tics);
    // place new food
    if(g_tics % theSettings->foodInterval == 0) {
      genobots->SetFoodRandom();
    }
    // evolve
    if(theSettings->evolve && (rand() % theSettings->evolutionChance == 0)) {
      genobots->Evolve(g_tics);
    }
    // update the UI
    UpdateStatusBar();
    UpdateBotPanel();
    Refresh(true);
    g_tics++;
    g_busy = false;
  }
}

// update the toolbar and menu
void genobotsFrame::UpdateUI() {
  GetToolBar()->EnableTool(ID_TOOL_NEW, !g_running);
  GetToolBar()->EnableTool(ID_TOOL_START, !g_running && genobots->superBots.size());
  GetToolBar()->EnableTool(ID_TOOL_STOP, g_running);
}

// update the statusbar
void genobotsFrame::UpdateStatusBar() {
  SetStatusText(wxString::Format(_("Tic: %d"), g_tics), 1);
  SetStatusText(wxString::Format(_("#Bots: %d"), genobots->GetBotCount()), 2);
}

// stop-button on the toolbar is clicked
void genobotsFrame::OnToolStopClicked(wxCommandEvent& event)
{
  OnStop();
}

// the timer is triggered: go one step further
void genobotsFrame::OnG_timer1Trigger(wxTimerEvent& event)
{
  OnStep();
}

// when the user changes the speed slider, actually change the tic-interval
void genobotsFrame::OnSpnSpeedChange(wxSpinEvent& event)
{
  sldSpeed->SetValue(event.GetPosition());
  g_interval = event.GetPosition();
  if(g_running) {
    OnStop();
    OnStart();
  }
}

void genobotsFrame::OnMenuFileNewSelected(wxCommandEvent& event)
{
  OnNew();
}

void genobotsFrame::OnMenuLoopStartSelected(wxCommandEvent& event)
{
  OnStart();
}

void genobotsFrame::OnMenuLoopStopSelected(wxCommandEvent& event)
{
  OnStop();
}

void genobotsFrame::OnMenuLoopStepSelected(wxCommandEvent& event)
{
  OnStep();
}

void genobotsFrame::OnButNewClick(wxCommandEvent& event)
{
  OnNew();
}

void genobotsFrame::OnNew() {
  // clear the grid
  genobots->Clear();
  //g_tics = 0;
  // set up the new size for the grid
  long newRows, newColumns;
  txtNumRows->GetValue().ToLong(&newRows);
  txtNumColumns->GetValue().ToLong(&newColumns);
  genobots->SetRows((int)newRows);
  genobots->SetColumns((int)newColumns);
  // new start
  genobots->Randomize(g_tics);
  genobots->SetFoodRandom();
  UpdateUI();
  UpdateStatusBar();
  genoCanvas->drawAll = true;
  Refresh(false);
}

void genobotsFrame::OnToolnewClicked(wxCommandEvent& event)
{
  OnNew();
}

// update the panel with bot properties
void genobotsFrame::UpdateBotPanel() {
  int i;
  if(genoCanvas->selected.first >= 0 && genoCanvas->selected.first < genobots->GetRows() &&
     genoCanvas->selected.second >= 0 && genoCanvas->selected.second < genobots->GetColumns() &&
     genobots->bots[genoCanvas->selected.first][genoCanvas->selected.second] != NULL) {
    // the user clicket on a bot
    bot *tmpBot = genobots->bots[genoCanvas->selected.first][genoCanvas->selected.second];
    stcBotSuperbot->SetLabel(tmpBot->mySuperbot->name);
    stcBotStarttic->SetLabel(wxString::Format(_("%d"), tmpBot->startTic));
    switch(tmpBot->direction) {
      case 0:
        stcBotDirection->SetLabel(_("North"));
        break;
      case 1:
        stcBotDirection->SetLabel(_("East"));
        break;
      case 2:
        stcBotDirection->SetLabel(_("South"));
        break;
      case 3:
        stcBotDirection->SetLabel(_("West"));
        break;
      default:
        stcBotDirection->SetLabel(wxEmptyString);
    }
    txtBotCode->Clear();
    wxFont tmpFont;
    tmpFont.SetWeight(wxFONTWEIGHT_BOLD);
    for (i = 0; i < (int)tmpBot->code.code.size(); i++) {
      wxString command = tmpBot->code.code[i]->command;
      if(tmpBot->lineNr == i) {
        txtBotCode->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, tmpFont));
      } else {
        txtBotCode->SetDefaultStyle(wxTextAttr());
      }
      txtBotCode->AppendText(wxString::Format(_("%s, %d, %d, %d\n"), command.c_str(), tmpBot->code.code[i]->intPrm1, tmpBot->code.code[i]->intPrm2, tmpBot->code.code[i]->intPrm3));
    }
    stcBotLineNr->SetLabel(wxString::Format(_("%d"), tmpBot->lineNr));
    stcBotHealth->SetLabel(wxString::Format(_("%d"), tmpBot->health));
    // memory
    for(i = 0; i < BOT_NUMMEMCELLS; i++) {
      grdBotMemory->SetCellValue(i, 0, wxString::Format(_("%d"), tmpBot->memory[i]));
    }
  } else {
    // no bot is selected
    stcBotSuperbot->SetLabel(wxEmptyString);
    stcBotStarttic->SetLabel(wxEmptyString);
    stcBotDirection->SetLabel(wxEmptyString);
    txtBotCode->Clear();
    stcBotLineNr->SetLabel(wxEmptyString);
    stcBotHealth->SetLabel(wxEmptyString);
    // memory
    grdBotMemory->ClearGrid();
  }
}

void GenoCanvas::OnLeftUp(wxMouseEvent& event) {
  wxPoint coor = computeCell(wxPoint(event.m_x, event.m_y));
  selected.first = coor.x;
  selected.second = coor.y;
  //wxMessageBox(wxString::Format(_("Clicked: (%d, %d)"), coor.x, coor.y), _("Left Click"));
  theFrame->UpdateBotPanel();
  Refresh();
}

void GenoCanvas::OnRightUp(wxMouseEvent& event) {
  wxPoint coor = computeCell(wxPoint(event.m_x, event.m_y));
  selected.first = coor.x;
  selected.second = coor.y;
  Refresh(false);
  if(genobots->bots[coor.x][coor.y] != NULL) {
    // show menu for bot
    theFrame->ShowMenuRightBot();
  } else {
    // show menu for no bot
    theFrame->ShowMenuRightNoBot();
  }
}

void genobotsFrame::ShowMenuRightBot() {
  PopupMenu(&menuRightBot);
}

void genobotsFrame::ShowMenuRightNoBot() {
  PopupMenu(&menuRightNoBot);
}

void genobotsFrame::OnMenuRightBotDeleteSelected(wxCommandEvent& event)
{
  genobots->DeleteBot(genoCanvas->selected.first, genoCanvas->selected.second);
  genoCanvas->drawAll = true;
  Refresh(false);
  UpdateStatusBar();
}

void genobotsFrame::OnMenuRightNoBotAddBotSelected(wxCommandEvent& event)
{
  unsigned int i;
  superBot *tmpSuperbot = NULL;
  wxTreeItemId tmpId = treeLoadedBots->GetSelection();
  for(i = 0; i < treeIds.size(); i++) {
    if(treeIds[i] == tmpId) {
      tmpSuperbot = treeSuperbots[i];
    }
  }
  if(tmpSuperbot == NULL) {
    // no superbot selected
    wxMessageBox(_("Please select a superbot on the left"), _("Error"));
  } else {
    genobots->AddBot(genoCanvas->selected.first, genoCanvas->selected.second, g_tics, tmpSuperbot);
    genoCanvas->drawAll = true;
    Refresh(false);
    UpdateStatusBar();
    UpdateBotPanel();
    // TODO (Ramon#5#): fix bug where the new bot doesn't immediately show
  }
}

void genobotsFrame::OnMenuFileSourceSelected(wxCommandEvent& event)
{
  SourceDialog dlgSource(this);
  dlgSource.ShowModal();
}

// update the tree with all the superbots
void genobotsFrame::UpdateTree() {
  unsigned int i;
  treeLoadedBots->DeleteChildren(treeRoot);
  treeIds.clear();
  treeSuperbots.clear();
  // create tree images
  wxImageList *treeImageList = new wxImageList(12, 12);
  wxImage *tmpTreeImage = new wxImage(_("./images/white.gif"));
  wxBitmap *tmpTreeBitmap = new wxBitmap(*tmpTreeImage);
  treeImageList->Add(*tmpTreeBitmap);
  for(i = 0; i < genobots->superBots.size(); i++) {
    tmpTreeImage = new wxImage(_("./images/tree.gif"));
    tmpTreeImage->RotateHue(genobots->superBots[i]->hue);
    tmpTreeBitmap = new wxBitmap(*tmpTreeImage);
    treeImageList->Add(*tmpTreeBitmap);
    delete tmpTreeBitmap;
    tmpTreeBitmap = NULL;
    delete tmpTreeImage;
    tmpTreeImage = NULL;
  }
  treeLoadedBots->AssignImageList(treeImageList);
  for(i = 0; i < genobots->superBots.size(); i++) {
    wxTreeItemId tmpId;
    tmpId = treeLoadedBots->AppendItem(treeRoot, genobots->superBots[i]->name, i + 1);
    treeIds.push_back(tmpId);
    treeSuperbots.push_back(genobots->superBots[i]);
  }
  treeLoadedBots->ExpandAll();
}

// add a new superbot
void genobotsFrame::OnMenuBotsAddSuperBotSelected(wxCommandEvent& event)
{
  // choose file to open
  wxString path;
  wxString FILETYPES = _T("Botcode files (*.gen)|*.gen|Text files (*.txt)|*.txt|All files|*.*");
  wxFileDialog* openFileDialog = new wxFileDialog(this, _T("Open botcode file"), wxEmptyString, wxEmptyString,
                                                  FILETYPES, wxOPEN, wxDefaultPosition);
	if(openFileDialog->ShowModal() == wxID_OK ) {
	  // file has been chosen
    unsigned int i = genobots->superBots.size();
    genobots->superBots.push_back(new superBot(i, g_tics));
    genobots->superBots[i]->codeFile = openFileDialog->GetPath();
    genobots->superBots[i]->ReadNameFromFile();
    genobots->superBots[i]->hue = colors[i % NUM_COLORS];
    genobots->superBots[i]->startTic= g_tics;
    UpdateTree();
    treeLoadedBots->SelectItem(treeIds.back());
    butBots->Enable(true);
    GetToolBar()->EnableTool(ID_TOOL_BOTS, true);
    GetToolBar()->EnableTool(ID_TOOL_START, true);
	}
}

void genobotsFrame::OnbutClearClick(wxCommandEvent& event)
{
  genoCanvas->genobots->Clear();
  UpdateUI();
  UpdateBotPanel();
  UpdateStatusBar();
  Refresh();
}

void genobotsFrame::OnButFoodClick(wxCommandEvent& event)
{
  genoCanvas->genobots->SetFoodRandom();
  Refresh();
}

void genobotsFrame::OnChkBotFollowClick(wxCommandEvent& event)
{
  theSettings->followBot = chkBotFollow->IsChecked();
}

void genobotsFrame::OnSldSpeedCmdScrollThumbTrack(wxScrollEvent& event)
{
  spnSpeed->SetValue(event.GetPosition());
  g_interval = event.GetPosition();
  if(g_running) {
    OnStop();
    OnStart();
  }
}

void genobotsFrame::OnSldSpeedCmdScrollChanged(wxScrollEvent& event)
{
  spnSpeed->SetValue(event.GetPosition());
  g_interval = event.GetPosition();
  if(g_running) {
    OnStop();
    OnStart();
  }
}

void genobotsFrame::OnSpnFoodChanceChange(wxSpinEvent& event)
{
  theSettings->chanceFood = event.GetPosition();
}

void genobotsFrame::OnSpnFoodIntervalChange(wxSpinEvent& event)
{
  theSettings->foodInterval = event.GetPosition();
}

void genobotsFrame::OnSpnFoodHealthChange(wxSpinEvent& event)
{
  theSettings->foodHealth = event.GetPosition();
}

void genobotsFrame::OnSpnInitBotChanceChange(wxSpinEvent& event)
{
  theSettings->initBotChance = event.GetPosition();
}

void genobotsFrame::OnSpnInitBotHealthChange(wxSpinEvent& event)
{
  theSettings->initBotHealth = event.GetPosition();
}

void genobotsFrame::OnChkEvolveClick(wxCommandEvent& event)
{
  theSettings->evolve = event.IsChecked();
  // update GUI
  chkMutate->Enable(event.IsChecked());
  spnEvoChance->Enable(event.IsChecked());
  spnEvoAmount->Enable(event.IsChecked());
  spnMutateChance->Enable(event.IsChecked() && chkMutate->IsChecked());
}

void genobotsFrame::OnChkUseLogClick(wxCommandEvent& event)
{
  theSettings->useLog = event.IsChecked();
}

void genobotsFrame::OnSpnEvoChanceChange(wxSpinEvent& event)
{
  theSettings->evolutionChance = event.GetPosition();
}

void genobotsFrame::OnSpnEvoAmountChange(wxSpinEvent& event)
{
  theSettings->evolutionAmount = event.GetPosition();
}

void genobotsFrame::OnSpnMutateChanceChange(wxSpinEvent& event)
{
  theSettings->mutateChance = event.GetPosition();
}

void genobotsFrame::OnMenuFilePlotSelected(wxCommandEvent& event)
{
  PlotWindow dlgPlot(this);
  for(unsigned int i = 0; i < genobots->superBots.size(); i++) {
    dlgPlot.thePlot->AddLayer(new MyPlot(genobots->superBots[i]));
  }
  dlgPlot.ShowModal();
}

void genobotsFrame::OnToolPlotClicked(wxCommandEvent& event)
{
  OnMenuFilePlotSelected(event);
}

void genobotsFrame::OnChkMutateClick(wxCommandEvent& event)
{
  theSettings->mutate = event.IsChecked();
  spnMutateChance->Enable(event.IsChecked());
}

void genobotsFrame::OnChcQualitySelect(wxCommandEvent& event)
{
  if(chcQuality->GetSelection() == 0) {
    theSettings->quality = wxIMAGE_QUALITY_NORMAL;
  } else {
    theSettings->quality = wxIMAGE_QUALITY_HIGH;
  }
  Refresh();
}

void genobotsFrame::OnButBotsClick(wxCommandEvent& event)
{
  genoCanvas->genobots->SetBotsRandom(g_tics);
  Refresh();
}

void genobotsFrame::OnToolAddBotsClicked(wxCommandEvent& event)
{
  OnButBotsClick(event);
}

void genobotsFrame::OnToolFoodClicked(wxCommandEvent& event)
{
  OnButFoodClick(event);
}

void genobotsFrame::OnToolBarClearClick(wxCommandEvent& event)
{
  OnbutClearClick(event);
}

void genobotsFrame::OnSpnFightDamageChange(wxSpinEvent& event)
{
  theSettings->fightDamage = event.GetPosition();
}

void genobotsFrame::OnToolBarSourceClick(wxCommandEvent& event)
{
  OnMenuFileSourceSelected(event);
}

void genobotsFrame::OnToolBarSuperbotClick(wxCommandEvent& event)
{
  OnMenuBotsAddSuperBotSelected(event);
}

void genobotsFrame::OnToolBarRestartClick(wxCommandEvent& event)
{
  genobots->superBots.clear();
  genobots->Clear();
  genoCanvas->drawAll = true;
  g_tics = 0;
  GetToolBar()->EnableTool(ID_TOOL_START, false);
  UpdateBotPanel();
  UpdateUI();
  UpdateTree();
  UpdateStatusBar();
  txtLog->Clear();
  Refresh(true);
}
